<template>
	<view>
		<view class="user">
			<image :src="userinfo.icon" v-if="!isLogin" class="tx" style="width: 80px; height: 80px; border-radius: 50%;"></image>
			<image src="../../static/head_icon.png" v-else class="tx" style="width: 80px; height: 80px; border-radius: 50%;"></image>
			<text class="name" v-if="isLogin">{{userinfo.name}}</text>
			<button v-else type="primary" 
			size="mini" style="width: 100px; height: 29px;" 
			@click="toLogin">点击登录</button>
		</view>
		
		<view class="container">
			<view style="width: 100%;">
				<view class="entries">
					<view style="width: 90%; height: 1rpx; background-color: #CCC;margin-bottom: 5px;"></view>
					<view class="entry">
						<image src="../../static/UserInfo.png" style="width: 40px; height: 40px;"></image>
						<text>个人信息</text>
						<image src="../../static/more.png" style="width: 40px; height: 40px;"></image>
					</view>
					<view style="width: 90%; height: 1rpx; background-color: #CCC;margin-bottom: 5px;"></view>
					<view class="entry">
						<image src="../../static/purchaseorder.png" style="width: 40px; height: 40px;"></image>
						<text>订单列表</text>
						<image src="../../static/more.png" style="width: 40px; height: 40px;"></image>
					</view>
					<view style="width: 90%; height: 1rpx; background-color: #CCC;margin-bottom: 5px;"></view>
					<view class="entry">
						<image src="../../static/modify-password.png" style="width: 40px; height: 40px;"></image>
						<text>修改密码</text>
						<image src="../../static/more.png" style="width:40px; height: 40px;"></image>
					</view>
					<view style="width: 90%; height: 1rpx; background-color: #CCC;margin-bottom: 5px;"></view>
					<view class="entry">
						<image src="../../static/yijianfankui.png" style="width: 40px; height: 40px;"></image>
						<text>意见反馈</text>
						<image src="../../static/more.png" style="width: 40px; height: 40px;"></image>
					</view>
					<view style="width: 90%; height: 1rpx; background-color: #CCC;margin-bottom: 5px;"></view>

				</view>
				<button type="primary" style="margin-top: 20px;" :disabled="!isLogin" @click="logout">退出</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo:{
					    // "icon": '/static/head_icon.png',
						"icon": '/static/my.png',
					    "name": null,
					    "email": null,
					    "telephone": null,
					    "department": null,
					    "major": null
				},
				isLogin:false
			}
		},
		onShow() {
			this.getUserInfo()
		},
		methods:{
			logout(){
				uni.setStorageSync('userinfo',null)
				this.isLogin=false
				this.getUserInfo()
			},
			getUserInfo(){
				let  userinfo=uni.getStorageSync('userinfo',null)
				if(userinfo){
					this.isLogin = true
					this.userinfo=userinfo
				}
				else{
					this.isLogin=false
					this.userinfo.icon='/static/my.png'
				}
			},
			toLogin(){
				uni.navigateTo({
					url: '/pages/my/login',
				});
			}
		}	
	}
</script>

<style>
	.user {
		/* background-color: azure; */
		display: flex;
		align-items: center;
		width: 100%;
		height: 180px;
		/* margin-top: 15px; */
		/* display: inline; */
	}

	.tx {
		margin-left: 40px;
	}

	.name {
		color: #9da7ad;
		padding-left: 50px;
	}

	page {
		/* width: 100%; */
	}

	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		/* background-color: #007AFF; */
		/* margin-top: 60px; */
	}

	.entries {
		margin-top: 12px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.entry {
		display: flex;
		flex-direction: row;
		height: 50px;
		width: 90%;
		justify-content: space-between;
	}

	.entry>text {
		display: block;
		height: 40px;
		width: 200px;
		margin-top: 13px;
	}

	button {

		width: 90%;
	}
</style>